package com.jie.listening;

import com.jie.entity.Article;
import com.jie.entity.Notice;
import com.jie.enums.ArticleFlowEvent;
import com.jie.netty.cline.IMClient;
import com.jie.netty.message.NoticeInfoMessage;
import com.jie.state.StateConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import static com.jie.constants.RabbitMQConstant.*;

/**
 * @Author: 杰
 * @Project :net-disk
 * @DateTime: 2024/7/4 10:57
 **/
@Component
@Slf4j
@RequiredArgsConstructor
public class NotifyListenConsumer {
    private final IMClient imClient;
    /**
     * 监听文章审核和保存
     *
     * @param noticeInfoMessage
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(value = NOTICE_QUEUE, durable = "true", autoDelete = "false"),
                    exchange = @Exchange(value = NOTICE_EXCHANGE),
                    key = NOTICE_KEY
            )}, containerFactory = "rabbitListenerContainerFactory")
    public void noticeMessageInfo(@Payload NoticeInfoMessage noticeInfoMessage) {
        log.info("收到消息：{}", noticeInfoMessage);
        //发送消息 这里可以做消息的手动ack和保证 后续扩展
        imClient.sendAllNotice(noticeInfoMessage);
        log.info("发送消息成功");
    }
}
